﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace Task3
{
    class Program
    {
        static void Main(string[] args)
        {
            
            try
            {
                //调用静态方法
                DBHelper.ShowCompany();

                Console.WriteLine("公司产品有以下如下：");
                //查询全部游戏
                #region
                


                string sql = "select ID,Name,Price,Stock,XiaoJi from Games";
                SqlDataReader dr = DBHelper.Select(sql);
                Console.WriteLine("序号\t游戏名称\t游戏价格\t库存数量\t小计");
                Console.WriteLine("*******************************************************************");
                while (dr.Read())
                {
                    string id = dr["ID"].ToString();
                    string name = dr["Name"].ToString();
                    string price = dr["Price"].ToString();
                    string stock = dr["Stock"].ToString();
                    string xiaoji = dr["XiaoJi"].ToString();
                    Console.WriteLine("{0}\t{1}\t{2}\t\t{3}\t\t{4}", id, name, price, stock, xiaoji);
                }

                Console.WriteLine("*******************************************************************");
                
                #endregion

                //增删改
                #region
                
                string sql2 = "insert into Games(Name,Price,Stock,XiaoJi) values('愤怒的小鸟','36','100','3,600.00')";
                bool result = DBHelper.ExecuteNonQuery(sql2);
                if (result)
                {
                    Console.WriteLine("添加成功！！");
                }
                else
                {
                    Console.WriteLine("添加失败！！");
                }
                
                #endregion
               
                //统计金额
                #region
               
                string sql3 = "select sum(Price*Stock) from Games";
                Console.WriteLine("游戏总金额：{0}",DBHelper.ExecuteScalar(sql3));
                
                #endregion

            }
            catch (Exception e)
            {

                Console.WriteLine(e.Message);
            }
            
            
        }
    }
}
